package com.utils.export;

import java.text.SimpleDateFormat;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.google.common.collect.Lists;
import com.utils.dateUtil.DateUtil;
import com.wf.course.model.bill.Bill;
 


public class GoodsBillExcelExporter{
	
	/**
	 * 类名称：GoodsOrderExcelExporter
	 * 类描述：实现微信对账单信息导出功能
	 * @version 1.0.0
	 */
	public void exportExcel(HttpServletResponse response,List<Bill> billList) {
		
		// 定义导出的Excel文件名称
		String fileName = "对账单信息表"+DateUtil.getDateString(new SimpleDateFormat("yyyyMMddHHmmss"));
		//数据处理
		
		//表头list
		List<String> headerList = Lists.newArrayList();
			headerList.add("序号");
			headerList.add("交易时间");
			headerList.add("公众号id");
			headerList.add("商户号");
			headerList.add("子商户号");
			headerList.add("设备号");
			headerList.add("微信订单号");
			headerList.add("商户订单号");
			headerList.add("用户标识");
			headerList.add("交易类型");
			headerList.add("交易状态");
			headerList.add("付款银行");
			headerList.add("货币种类");
			headerList.add("总金额");
			headerList.add("代金券或立减优惠金额");
			headerList.add("微信退款单号");
			headerList.add("商户退款单号");
			headerList.add("退款金额");
			headerList.add("代金券或立减优惠退款金额");
			headerList.add("退款类型");
			headerList.add("退款状态");
			headerList.add("商品名称");
			headerList.add("商户数据包");
			headerList.add("手续费");
			headerList.add("费率");
		
		//数据集合
		List<List<String>> dataList = Lists.newArrayList();
		//序号
		int colNum = 0;
		//遍历数据
		for(Bill bill : billList){
			colNum++;
			Object value;
			
			//每一行的数据list
			List<String> dataRowList = Lists.newArrayList();
			//序号
			dataRowList.add(String.valueOf(colNum));
			//交易时间
			value = bill.getTradetime();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//公众号id
			value = bill.getGhid();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//商户号
			value = bill.getMchid();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//子商户号
			value = bill.getSubmch();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			//设备号
			value = bill.getDeviceid();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			//微信订单号
			value = bill.getWxorder();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			//商户订单号
			value = bill.getBzorder();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//用户标识
			value = bill.getOpenid();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//交易类型
			value = bill.getTradetype();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			
			//交易状态
			value = bill.getTradestatus();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//付款银行
			value = bill.getBank();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			
			//货币种类
			value = bill.getCurrency();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//总金额
			value = bill.getTotalmoney();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			//代金券或立减优惠金额
			value = bill.getRedpacketmoney();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			//微信退款单号
			value = bill.getWxrefund();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//商户退款单号
			value = bill.getBzrefund();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//退款金额
			value = bill.getRefundmoney();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//代金券或立减优惠退款金额
			value = bill.getRedpacketrefund();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//退款类型
			value = bill.getRefundtype();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//退款状态
			value = bill.getRefundstatus();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//商品名称
			value = bill.getProductname();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//商户数据包
			value = bill.getBzdatapacket();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			//手续费
			value = bill.getFee();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			//费率
			value = bill.getRate();
			value = value == null ? "" : value;
			dataRowList.add(String.valueOf(value));
			
			
			dataList.add(dataRowList);
			
		}
		
		//导出数据
		ExportExcel.doExportExcel(response, fileName, headerList, dataList);
	}
}
